﻿Imports System.Data.SqlClient
Public Class dbFormula
    Dim Var As New varDeclare

    Public Function FormulaList(ByVal Comp As String) As DataSet
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)

        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT * FROM vListFormula WHERE Tipe = '0'"
        command.Parameters.Add("@CompID", SqlDbType.VarChar).Value = Comp
        adapter = New SqlDataAdapter(command)
        adapter.Fill(ds)
        connection.Close()
        Return ds
    End Function

    Public Function FormulaDetail(ByVal Comp As String, ByVal FormulaID As String) As DataSet
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.ConnString)

        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "proc_FormulaDetail"
        command.Parameters.Add("@CompID", SqlDbType.VarChar).Value = Comp
        command.Parameters.Add("@FormulaID", SqlDbType.VarChar).Value = FormulaID
        adapter = New SqlDataAdapter(command)
        adapter.Fill(ds)
        connection.Close()
        Return ds
    End Function

    Public Function GetItemDetailList() As DataSet
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)

        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT * FROM vPriceCalc WHERE Stat = 'A'"
        adapter = New SqlDataAdapter(command)
        adapter.Fill(ds)
        connection.Close()
        Return ds
    End Function

    Public Function deleteFormula(ByVal FormulaID As String, ByVal CompID As String) As Boolean
        Dim connection As SqlConnection
        Dim command As New SqlCommand
        connection = New SqlConnection(Var.ConnString)

        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "proc_FormulaDelete"
        command.Parameters.Add("@FormulaID", SqlDbType.VarChar).Value = FormulaID
        command.Parameters.Add("@CompID", SqlDbType.VarChar).Value = CompID
        Dim result As Object = command.ExecuteScalar()
        connection.Close()
        Return Convert.ToBoolean(result)
    End Function
End Class
